package com.thwcompany.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//发布——订阅模式的配置,包括两个队列和对应的订阅者(共2个消费者),发布者的交换机类型使用fanout(子网广播),两根网线binding用来绑定消息队列到交换机
@Configuration
@SuppressWarnings("all")
public class FanoutExchangeConfig {
	@Bean
	public FanoutExchange fanoutExchange(){
		FanoutExchange fanoutExchange=new FanoutExchange("fanout");
		return fanoutExchange;
	}
 	@Bean
    public Queue fanoutQueue1() {
       Queue queue=new Queue("fanoutqueue1");
       return queue;
    }
 	@Bean
    public Queue fanoutQueue2() {
       Queue queue=new Queue("fanoutqueue2");
       return queue;
    }

	//============================================================
 	@Bean
 	public Binding binding1(){
		Binding binding=BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
 		return binding;
 	}
	//============================================================
 	@Bean
 	public Binding binding2(){
 		Binding binding=BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
 		return binding;
 	}
 	
}
